﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OopDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("A：三角形, V：倒三角形, E：矩形, T：梯形");
            Console.WriteLine("请输入所需要的图像代号，或者输入'Q' 退出");
            var input = Console.ReadLine();
            while (input != "Q")
            { 
                var shape = ShapeFactory(input);
                if (shape == null)
                {
                    Console.WriteLine("无效代号");
                    continue;
                }
                Console.ForegroundColor = ConsoleColor.Green; //绿色
                shape.Draw();
                Console.ForegroundColor = ConsoleColor.White; //白色
                Console.WriteLine("可以继续输入图像代号");
                
                input = Console.ReadLine();
            }

            Console.WriteLine("程序退出");
        }

        /// <summary>
        /// 根据输入产生 图行
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        static IShape ShapeFactory(string key)
        {
            switch (key)
            {
                case "A":
                    return new Triangle();

                case "V":
                    return new InvertedTriangle();

                case "E":
                    return new Rectangle();

                case "T":
                    return new Trapezoid();

                default:
                    break;
            }
            return null;
        }

    }
}
